﻿using System;
using SmartHRMS.Model.Account;
using System.Collections.Generic;

namespace SmartHRMS.NhibernateRepository
{
    public class UserRepository : BaseRepository<User>, IUserRepository
    {
        #region IUserRepository Members

        public System.Collections.Generic.IList<User> FindUsersByEmployeeCode(string employeeCode)
        {
            var result = SessionFactory.GetCurrentSession().CreateQuery("select o from User o where o.EmployeeCode like :EmployeeCode").SetString("EmployeeCode", employeeCode);
            IList<User> users = result.List<User>();
            return users;
        }

        public System.Collections.Generic.IList<User> FindUsersByName(string userName)
        {
            var result = SessionFactory.GetCurrentSession().CreateQuery("select o from User o where o.UserName like :UserName").SetString("UserName", userName);
            IList<User> users = result.List<User>();
            return users;
        }

        public bool AddToRole(Guid roleId)
        {
            throw new NotImplementedException();
        }

        public bool RemoveRole(Guid roleId)
        {
            throw new NotImplementedException();
        }

        public bool IsUserNameExist(string userName)
        {
            var result=SessionFactory.GetCurrentSession().CreateQuery("select o from User o where o.UserName = :UserName").SetString("UserName", userName);
            if (result.List().Count > 0)
            {
                return true;
            }
            return false;
        }

        #endregion
    }
}
